<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
if(isset($_SESSION['lang']))
    require_once "./language_files/viewConferencesPerPage_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/viewConferencesPerPage_en.php";

require_once "functions.php";
?>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <style type="text/css">
        #Status     {margin-left:0px; top: 240px; width: 100px; height:0px; position: inherit}
        #SetPerPage {margin-left: 250px; top: 0px; width: 150px; height:15px; position: relative}
        #JumpToPage {margin-left: 500px; top: -28px; width: 150px; height:15px; position: relative}

        #Previous               {margin-left: 250px; top: 300px; width: 150px; height:15px; position: inherit}
        #PreviousInactive       {margin-left: 250px; top: 300px; width: 150px; height:15px; position: inherit}
        #Next                   {margin-left: 500px; top: 28px; width: 150px; height:15px; position: relative}
        #NextInactive           {margin-left: 500px; top: 28px; width: 150px; height:15px; position: relative}

    </style>
</html>
<?php
//Connect to database

//Intiating per page to 5 conferences per page
if($_GET['pp'] > 0 || $_GET['pp'] == Null)
{
    $m=( isset($_GET['pp']) )?(int)$_GET[pp]:5;
    $pp=mysql_real_escape_string($m);
}
else
{
    echo '<script type="text/javascript">','alert("Error: You can not set the view per page to this value!")','</script>';
    $m=5;
    $pp=mysql_real_escape_string($m);
}

//Calculating the total number of pages needed to view the information
$result=mysql_query("SELECT conference_id FROM conference") Or die(mysql_error());
$users_nm=mysql_num_rows($result);
$total_pages=(int)ceil($users_nm / $pp);

//Intiating the initial page and handling inputs exceptions
if($_GET['p'] <= $total_pages && $_GET['p'] > 0 || $_GET['p'] == Null)
{
    $p=( isset($_GET['p']) )?(int)$_GET[p]:1;
}
else
{
    if($_GET['p'] <= 0 && $_GET['p'] != null)
    {
        $p=1;
        echo '<script type="text/javascript">','alert("Error: You Can Not Jump to the Specified Page")','</script>';
    }
    else
    {
        $p=$total_pages;
        echo '<script type="text/javascript">','alert("Error: You Can Not Jump to the Specified Page")','</script>';
    }
}
$start=(int)( $p - 1 ) * $pp;
$result=mysql_query("SELECT conference_id, long_name FROM conference LIMIT $start, $pp") Or die(mysql_error());
echo '<table width="100%">
<tr>
<td><b>' . $lang['conf'] . '</b>
</td>
</tr>';
while($row=mysql_fetch_assoc($result))
{
    $long=formatText_safe($row['long_name']);
    echo "<tr>
<td>{$long}</td>
<td><a href='conferencePage.php?conference_id={$row['conference_id']}'>" . $lang['go_conf'] . " </a </td>
</tr>";
}
echo '</table>';
if($total_pages > 1 && $p <= $total_pages)
{
    for($x=1; $x <= $total_pages && $x <= 6; $x++)
    {
        echo '<a href="?p=' . $x . '&pp=' . $pp . '">' . $x . '</a> ';
    }
}
?>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="Status">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="SetPerPage" enctype="multipart/form-data">
                <p><strong><?PHP echo $lang['current_page'] . " " . $p . " " . $lang['of'] . " " . $total_pages . " " . $lang['view'] . " " . $pp . $lang['conf_page']?></strong></p>
            </form>
        </div>
        <div id="SetPerPage">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="SetPerPage" enctype="multipart/form-data">
                <p><?php echo $lang['display']?>
                    <input name="pp" value="<?PHP print $pp;?>"size="5" maxlength="100">
                </p>
                <p>
                    <input name="Set" type="submit" value="<?php echo $lang['set'];?>">
                </p>
            </form>
        </div>
        <div id="JumpToPage">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="JumpToPage" enctype="multipart/form-data">
                <p><?php echo $lang['jump']?>
                    <input name="p" value="<?PHP print $p;?>" size="5" maxlength="100">
                </p>
                <p>
                    <input name="Go" type="submit" value="<?php echo $lang['go'];?>">
                </p>
                <input name="pp" type="hidden"  value="<?php echo $pp;?>">
            </form>
        </div>
<?php if($p < $total_pages):?>
            <div id="Next">
                <form action= 'ViewConferencesPerPage.php' method="GET" name="Next" enctype="multipart/form-data">
                    <p>
                        <input name="Next" type="submit" value="<?php echo $lang['next'];?>">
                    </p>
                    <input name="pp" type="hidden"  value="<?php echo $pp;?>">
                    <input name="p" type="hidden"  value="<?php echo $p + 1;?>">
                </form>
            </div>
        <?php else:?>
            <div id="NextInactive">
                <form action= 'ViewConferencesPerPage.php' method="GET" name="NextInactive" enctype="multipart/form-data" disabled="disabled">
                    <p>
                        <input name="NextInactive" type="submit" value="<?php echo $lang['next'];?>" disabled="disabled">
                    </p>
                    <input name="pp" type="hidden"  value=" <?php echo $pp;?> ">
                    <input name="p" type="hidden"  value=" <?php echo $p + 1;?>">
<?php endif;?>
            </form>
        </div>

<?php if($p == 1):?>
            <div id="PreviousInactive">
                <form action= 'ViewConferencesPerPage.php' method="GET" name="PreviousInactive" enctype="multipart/form-data" disabled="disabled">
                    <p>
                        <input name="PreviousInactive" type="submit" value="<?php echo $lang['pre'];?>" disabled="disabled">
                    </p>
                    <input name="pp" type="hidden"  value="<?php echo $pp;?>">
                    <input name="p" type="hidden"  value="<?php echo $p - 1;?>">
                </form>
            </div>
        </body>
    </html>
<?php else:?>
    <div id="Previous">
        <form action= 'ViewConferencesPerPage.php' method="GET" name="ViewConferences" enctype="multipart/form-data">
            <p>
                <input name="Next" type="submit" value="<?php echo $lang['pre'];?>">
            </p>
            <input name="pp" type="hidden"  value="<?php echo $pp;?>">
            <input name="p" type="hidden"  value="<?php echo $p - 1;?>">
        </form>
    </div>
<?php endif;?>
</body>
</html>